import { createRouter, createWebHashHistory, RouteLocationNormalized, RouteRecordRaw, RouterOptions } from 'vue-router'
import Home from '../index/views/Home.vue'
import User from '../index/views/User/index.vue'
import questionindex from '../index/views/Question/questionindex.vue'
import questiontype from '../index/views/Question/questiontype.vue'
import questionbankindex from '../index/views/Questionbank/questionbankindex.vue'
import questionbank from '../index/views/Questionbank/questionbank.vue'
import activity from '../index/views/Activity/activity.vue'
import activityindex from '../index/views/Activity/index.vue'
import articleindex from '../index/views/Article/index.vue'
import article from '../index/views/Article/article.vue'
import match from '../index/views/match/index.vue'
import matchindex from '../index/views/match/matchindex.vue'
import matchquestion from '../index/views/match/matchquestion.vue'
import matchend from '../index/views/match/matchend.vue'
import TEam from '../index/views/team/index.vue'
import TEamdynamic from '../index/views/team/dynamic.vue'
import TEammatch from '../index/views/team/match.vue'
import TEamquestion from '../index/views/team/question.vue'
import TEamquestionbank from '../index/views/team/questionbank.vue'
import TEamsett from '../index/views/team/sett.vue'
import TEamtask from '../index/views/team/task.vue'
import TEamnotice from '../index/views/team/notice.vue'
import TEamuser from '../index/views/team/user.vue'
import TEamdata from '../index/views/team/data.vue'
import Mydata from '../index/views/User/mydata.vue'
import Myquestionbank from '../index/views/User/questionbank.vue'
import Myquestion from '../index/views/User/question.vue'
import Mychangequestion from '../index/views/User/questionindex.vue'
import Mychangequestionbank from '../index/views/User/questionbankindex.vue'
import Myaddteam from '../index/views/User/myaddteam.vue'
import Userqustion from '../index/views/userquestion/index.vue'
import Mynotice from '../index/views/notice/index.vue'
import Mytest from '../index/views/test/index.vue'
import testindex from '../index/views/test/testindex.vue'
import testquestion from '../index/views/test/testquestion.vue'
import testend from '../index/views/test/testend.vue'
import Logs from '../index/views/logs/index.vue'
import Activitydata from '../index/views/Activity/activitydata.vue'
import usertestcase from '../index/views/Question/watchtestcase.vue'
import Chart from '../index/views/team/chart.vue'
import Rank from '../index/views/team/rank.vue'
import Data2 from '../index/views/team/data2.vue'
import Teamuserdata from '../index/views/team/teamuserdata.vue'
import Teamdata from '../index/views/team/Teamdata.vue'
import TeamMatcdatahVue from '../index/views/team/matchdata.vue'
import { jilurizhi } from '../api'
import TeamcreatedActivity from '../index/views/team/createdactivit.vue'
import TEamjob from '../index/views/team/teamjob.vue'
import Createdteamjob from '../index/views/team/createdteamjob.vue'
import questionLeaderboardVue from '../index/views/team/questionLeaderboard.vue'
import Submission from '../index/views/Question/Submission.vue'
import testcases from '../index/views/Question/testcases.vue'
import Questioncontext from '../index/views/Question/context.vue'
import discuss from '../index/views/Question/discuss.vue'
import usersolution from '../index/views/Question/usersolution.vue'
import integral from '../index/views/User/integral.vue'
import teamfile from '../index/views/team/oss.vue'
import Login from './views/login.vue'
import sciencechat from '../sciencechat/App.vue'
import scienceuser from './views/scienceuser.vue'

function toID(rote: RouteLocationNormalized): Record<string, any> {
  return {
    ID: Number(rote.params.ID)
  }

}

const routes: RouteRecordRaw[] = [
  {
    path: '/main',
    name: '科学中心',
    component: sciencechat,

  },
  {
    path: '/scienceuser',
    name: '人员管理',
    component: scienceuser,

  },
  {
    path: '/Login',
    name: '登录',
    component: Login
  },
  {
    path: '/',
    name: '首页',
    component: Home
  },
  {
    path: '/userqustion',
    name: '答题记录',
    component: Userqustion
  },
  {
    path: '/mydata',
    name: '我的资源',
    component: Mydata,
    redirect: {
      name: '我的题库'
    },
    children: [
      {
        path: 'question',
        name: '我的题库',
        component: Myquestion,
      },
      {
        path: 'questionbank',
        name: '我的题单',
        component: Myquestionbank,
      },
      {
        path: 'changequestionbank/:ID',
        name: '修改我的题单',
        component: Mychangequestionbank,
        props: toID
      },
      {
        path: 'changequestion',
        name: '修改我的题库',
        component: Mychangequestion,
      },
      {
        path: 'myaddteam/:ID',
        name: '加入团队',
        component: Myaddteam,
        props: toID
      },
    ]
  },
  {
    path: '/usertestcase',
    name: '贡献测试点查询',
    component: usertestcase
  },
  {
    path: '/question',
    name: '题库',
    component: questionindex
  },
  {
    path: '/question/:ID',
    name: '题目',
    component: questiontype,
    props: toID,
    children: [
      // {
      //   path: 'Questioncontext',
      //   name: '题目详情',
      //   component: Questioncontext
      // },
      {
        path: 'Submission',
        name: '我的提交',
        component: Submission
      },
      {
        path: 'discuss',
        name: '问题讨论',
        component: discuss
      },
      {
        path: 'testcases',
        name: '贡献测试点',
        component: testcases
      },
      {
        path: 'usersolution',
        name: '题目题解',
        component: usersolution
      },
    ]
  },
  {
    path: '/questionbank/:ID',
    name: '题库列表',
    component: questionbank,
    props: toID
  },
  {
    path: '/questionbank',
    name: '题单',
    component: questionbankindex
  },
  {
    path: '/activity',
    name: '竞赛',
    component: activityindex
  },
  {
    path: '/activity/:ID',
    name: '比赛详情',
    component: activity,
    props: toID
  },
  {
    path: '/activitydata/:ID',
    name: '比赛数据详情',
    component: Activitydata,
    props: toID

  },
  {
    path: '/article/:ID',
    name: '动态详情',
    component: article,
    props: toID
  },
  {
    path: '/article',
    name: '动态',
    component: articleindex
  },
  {
    path: '/user',
    name: '用户',
    component: User,
  },
  {
    path: '/integral',
    name: '积分',
    component: integral,
  },
  {
    path: '/notice',
    name: '我的通知',
    component: Mynotice,
  },

  {
    path: '/chart/:ID',
    name: '团队数据图标',
    component: Chart,
    props: toID,
  },
  {
    path: '/test/:ID',
    name: '测评',
    component: Mytest,
    props: toID,
    redirect: {
      name: '测评首页'
    },
    children: [
      {
        name: '测评首页',
        path: 'index',
        component: testindex,
      },
      {
        name: '测评答题',
        path: 'question/:index',
        component: testquestion,
        props: true
      },
      {
        name: '测评结束',
        path: 'testend',
        component: testend,
      }
    ]
  },
  {
    path: '/match/:ID',
    name: '比赛',
    component: match,
    redirect: {
      name: '比赛首页'
    },
    props: toID,


    children: [
      {
        name: '比赛首页',
        path: 'index',
        component: matchindex,
      },
      {
        name: '比赛答题',
        path: 'question/:index',
        component: matchquestion,
        props: true
      },
      {
        name: '比赛结束',
        path: 'matchend',
        component: matchend,
      }
    ]
  },
  {
    path: '/teamactivity/:ID',
    name: '创建比赛',
    component: TeamcreatedActivity,
    props: toID,
  },
  {
    path: '/createdteamjob/:ID',
    name: '创建工作',
    component: Createdteamjob,
    props: toID,
  },
  {
    path: '/team/:ID',
    name: '团队',
    component: TEam,
    props: toID,
    redirect: {
      name: '团队动态'
    },
    children: [
      {
        path: 'question',
        name: '团队题目',
        component: TEamquestion,
      },
      {
        path: 'questionbank',
        name: '团队题单',
        component: TEamquestionbank,
      },
      {
        path: 'match',
        name: '团队比赛',
        component: TEammatch,
      },
      {
        path: 'dynamic',
        name: '团队动态',
        component: TEamdynamic,
      },
      {
        path: 'teamfile',
        name: '团队文件',
        component: teamfile,
      },
      {
        path: 'teamdata',
        name: '团队数据',
        component: TEamdata,
        redirect: {
          name: '成员排行榜'
        },
        // redirect: to => {
        //   console.log(to)
        //   // 方法接收目标路由作为参数
        //   // return 重定向的字符串路径/路径对象
        //   return { path: '/', query: { q: to.params.searchText } }
        // },
        children: [
          {
            path: 'rank',
            name: '成员排行榜',
            component: Rank,
          },
          {
            path: 'questionLeaderboard',
            name: '题目排行榜',
            component: questionLeaderboardVue
          },
          {
            path: 'questiondata',
            name: '成员测评记录',
            component: Data2,
          },
          {
            path: 'teamuserdata',
            name: '成员数据统计',
            component: Teamuserdata,
          },
          {
            path: 'teammatchdata',
            name: '成员比赛记录',
            component: TeamMatcdatahVue,
          },
        ]
      },
      {
        path: 'sett',
        name: '团队设置',
        component: TEamsett,
      },
      {
        path: 'task',
        name: '团队任务',
        component: TEamtask,
      },
      {
        path: 'job',
        name: '团队工作',
        component: TEamjob,
      },
      {
        path: 'teamnotice',
        name: '团队通知',
        component: TEamnotice,
      },
      {
        path: 'user',
        name: '团队组员',
        component: TEamuser,
      },
    ]
  },

]

const router = createRouter({
  history: createWebHashHistory(),
  routes,

})

// router.beforeEach((to, from) => {
//   const name = ['科学中心', '人员管理']
//   if (name.includes(to.name)) {
//     const nav = document.getElementById('nav')
//     if (nav) {
//       nav.style.display = 'none'
//     }
//   } else {
//     const nav = document.getElementById('nav')
//     if (nav) {
//       nav.style.display = 'block'
//     }
//   }
// })

export default router
